﻿using System;
using System.Globalization;
using System.Windows.Data;
namespace CoreModule.Converters
{
    /// <summary>
    /// Sbp 压力 转百分比。
    /// </summary>
    public class SbpPressureToProgressConverter : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        public double SourceBegin { get; set; } = 40;
        /// <summary>
        /// 
        /// </summary>
        public double SourceEnd { get; set; } = 140;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var intValue = (int)value;
            if (intValue <= SourceBegin)
            {
                return 0;
            }
            else if (intValue <= 60)
            {
                return (int)((intValue - 40));
            }
            else if (intValue <= 90)
            {
               return (int)( (intValue - 60)*33.3/30+ 20);
            } else if (intValue <= 100)
             {
                return (int)((intValue - 90)*13.3 /10.0 + 53.3);
            }
            else if (intValue <= 110)
            {
                return (int)((intValue - 100) *13.4 /10 +66.6);
            }
            else if (intValue <= 140)
            {
                return Math.Min(100, (int)((intValue - 110) * 20 / 30 + 80));
            }
            else
            {
                return 100;
            }
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
